<template>
  <div class="app-container">
    <!-- 查询框 -->
    <div class="filter-container">
      <el-input
        v-model="pageParam.model.patientName"
        style="width: 200px;"
        placeholder="姓名查询..."
        class="filter-item"
        @keyup.enter.native="handleFilter"
        @input="handleFilter"
      />
    </div>

    <!-- 表格 -->
    <el-table :data="list" fit highlight-current-row style="width: 100%;" @sort-change="sortChange">
      <!--              @expand-change="getPatientInfoAndRecord">-->

      <el-table-column class="filter-item" type="expand">
        <template slot-scope="{row}">
          <el-form label-position="left" inline class="demo-table-expand">
            <!-- 行数据详情字段 -->
            <el-form-item label="年龄">
              <span>{{ row.patient.age }}</span>
            </el-form-item>
            <el-form-item label="身份证">
              <span>{{ row.patient.identityNo }}</span>
            </el-form-item>
            <el-form-item label="医保证">
              <span>{{ row.patient.medicalId }}</span>
            </el-form-item>
            <el-form-item label="联系人姓名">
              <span>{{ row.patient.realName }}</span>
            </el-form-item>
            <el-form-item label="联系人电话">
              <span>{{ row.patient.tellphone }}</span>
            </el-form-item>
            <el-form-item label="诊断时间">
              <span>{{ row.record.checkTime }}</span>
            </el-form-item>
            <el-form-item label="病症">
              <span>{{ row.record.symptom }}</span>
            </el-form-item>
            <el-form-item label="诊断">
              <span>{{ row.record.diagnosis }}</span>
            </el-form-item>
            <el-form-item label="过敏史">
              <span>{{ row.record.allergy }}</span>
            </el-form-item>
            <el-form-item label="传染性疾病">
              <span v-if="row.record.isInfectious=='0'">否</span>
              <span v-else>是</span>
            </el-form-item>

          </el-form>
        </template>
      </el-table-column>
      <el-table-column prop="no" label="住院编号" />

      <el-table-column prop="bedNo" label="房间号" />

      <el-table-column prop="patient.realName" label="患者姓名" />

      <el-table-column prop="patient.gender" label="性别">
        <template slot-scope="scope">
          <span v-if="scope.row.patient.gender==0">女</span>
          <span v-else>男</span>
        </template>
      </el-table-column>

      <el-table-column prop="patient.tellphone" label="联系电话" />
    </el-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="getListByPage"
    />
  </div>
</template>

<script>

// application api
import {
  getApplication
} from '@/api/application/application'

// 导入组件 分页 记得声明组件
import Pagination from '@/components/Pagination'

export default {
  components: { // 在这里声明组件
    Pagination
  },
  data() {
    return {
      list: [], // 列表数据
      total: 0,
      listQuery: { // 分页 排序  查询参数
        pageNum: 1,
        pageSize: 5
      },
      pageParam: {
        pageNum: 1,
        pageSize: 5,
        model: {
          'patientName': undefined
        },
        orderParams: [
          ''
        ],
        superSearchKeyWord: ''
      }
    }
  },
  created() {
    this.getListByPage()
  },
  methods: {
    handleFilter() {
      this.listQuery.page = 1
      this.getListByPage()
    },
    sortChange(val) {
      // console.log("排序参数",val)
      const prop = val.prop
      const order = val.order === 'ascending' ? 'asc' : 'desc'
      const orderParam = 'apply_time' + ' ' + order
      // console.log(orderParam)
      this.pageParam.orderParams.push(orderParam)
      console.log(this.pageParam.orderParams)
      this.getListByPage()
    },
    // 显示当前页列表带分页
    getListByPage() {
      this.pageParam.pageNum = this.listQuery.pageNum
      this.pageParam.pageSize = this.listQuery.pageSize

      console.log(this.pageParam.orderParams)
      // 加载申请列表
      getApplication(this.pageParam).then(res => {
        // console.log(res)
        this.list = res.content.list
        this.total = res.content.total
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style>
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
